import request from '@/api/request'

export interface Entry {
  id: number
  owner_id: number
  title?: string
  content?: string
  mood?: number
  date?: string
  created_at?: string
  updated_at?: string
  [k: string]: any
}

export async function listEntries(params:{userId: number,title: string}) {
    console.log('Listing entries with params:', params);
    return request<{ list: Entry[]; total: number }>({
        url: '/entries/list',
        method: 'GET',
        params,
  })
}

export async function getEntry(id: number | string) {
  return request<Entry>({
    url: `/entries/${id}`,
    method: 'GET',
  })
}

export async function createEntry(data: Partial<Entry>) {
    console.log('Creating entry with data:', data);
  return request<Entry>({
    url: '/entries/create',
    method: 'POST',
    data,
  })
}

export async function updateEntry(id: number | string, data: Partial<Entry>) {
  return request<Entry>({
    url: `/entries/${id}`,
    method: 'PUT',
    data,
  })
}

export async function deleteEntry(id: number | string) {
  return request<null>({
    url: `/entries/${id}`,
    method: 'DELETE',
  })
}
